<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of fitLogLawV2</title>
  <meta name="keywords" content="fitLogLawV2">
  <meta name="description" content="This function fits a log law of the form u/u* = 1/kappa*ln(z/zo) to the given data">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
  <script type="text/javascript">
    if (top.frames.length == 0) { top.location = "../../index.html"; };
  </script>
</head>
<body>
<a name="_top"></a>
<!-- ../menu.html trunk --><!-- menu.html utils -->
<h1>fitLogLawV2
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>This function fits a log law of the form u/u* = 1/kappa*ln(z/zo) to the given data</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [ustar,zo,cod] = fitLogLawV2(u,z,h) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment"> This function fits a log law of the form u/u* = 1/kappa*ln(z/zo) to the given data
 and returns u*, zo, and the sum of the squared residuals ssr.</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="ADCP_DispCoef.html" class="code" title="function [k,kc,Eyc,Q] = ADCP_DispCoef(beddepth,travdist,vertdepth,downstvel,startDist,endDist,extrp,extend_to_banks,banktype);">ADCP_DispCoef</a>	This program computes the longitudinal dispersion coefficient from ADCP</li><li><a href="STA_MeanProfileV2.html" class="code" title="function sta = STA_MeanProfileV2(fitProf,units,StrDir)">STA_MeanProfileV2</a>	Compute the mean profile from stationary measurements at a point.</li></ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [ustar,zo,cod] = fitLogLawV2(u,z,h)</a>
0002 
0003 <span class="comment">% This function fits a log law of the form u/u* = 1/kappa*ln(z/zo) to the given data</span>
0004 <span class="comment">% and returns u*, zo, and the sum of the squared residuals ssr.</span>
0005 
0006 <span class="comment">% P.R. Jackson, 11-16-10</span>
0007 
0008 <span class="comment">%Example:</span>
0009 
0010 <span class="comment">% clear all</span>
0011 <span class="comment">% z = 5:50; u = 0.046/0.41*log(z/0.008);</span>
0012 <span class="comment">% u = u + (2*rand(size(u))-1).*0.05.*u;</span>
0013 <span class="comment">% [ustar,zo] = fitLogLawV2(u,z);</span>
0014 <span class="comment">% figure(1); clf; plot(u,z); hold on</span>
0015 <span class="comment">% plot(upred,zpred,'r-'); hold on</span>
0016 <span class="comment">% plot(upred+delta',zpred,'r:',upred-delta',zpred,'r:'); hold on</span>
0017 
0018 <span class="comment">%figure(1); clf; plot(u,z,'ko-'); xlim([0 max(u)]); ylim([0 max(z)]);pause</span>
0019 
0020 <span class="keyword">if</span> (nargin &lt; 3)
0021     h = max(z);
0022 <span class="keyword">end</span>
0023 
0024 zpred = linspace(0,h,100);
0025 
0026 kappa = 0.41; <span class="comment">% Von Karman constant</span>
0027 
0028 [p,S] = polyfit(log(z),u,1);
0029 
0030 ustar = kappa*p(1);
0031 
0032 zo = exp(-p(2)/p(1));
0033 
0034 ssr = S.normr.^2;
0035 
0036 sstot = sum((u - mean(u)).^2);
0037 
0038 cod = 1 - ssr./sstot; <span class="comment">%Coefficient of determination (r^2)</span>
0039 
0040 
0041 
0042 
0043 
0044 
0045 
0046 
0047 
0048 
0049</pre></div>
<hr><address>Generated on Tue 30-Apr-2013 10:18:12 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
</body>
</html>